package com.xiu.json.engine;

import com.xiu.json.exception.ParseJsonException;

/**
 * @Author: tjc
 * @description
 * @Date Created in 0:14 2022-04-03
 */
public class Token {
    public static final Token END = new Token(TokenType.END, "");
    public static final Token NULL = new Token(TokenType.NULL, "null");

    TokenType type;
    String value;

    public Token(TokenType type, String value) {
        this.type = type;
        this.value = value;
    }

    public static Token symbol(String str) {
        return new Token(TokenType.SYMBOL, str);
    }

    public static Token number(String str) {
        return new Token(TokenType.NUMBER, str);
    }

    public static Token string(String str) {
        return new Token(TokenType.STRING, str);
    }

    public static Token BOOL(String str) {
        if("false".equals(str)) {
            return new Token(TokenType.BOOL, "false");
        }
        if("true".equals(str)) {
            return new Token(TokenType.BOOL, "true");
        }
        throw new IllegalStateException("param is 'false' or 'true'," + str);
    }
}
